package it.mauriziulu.android.ehttpexecutors.handler;

import it.mauriziulu.android.ehttpexecutors.request.EHttpRequest;
import it.mauriziulu.android.ehttpexecutors.response.EHttpResponseContainer;
import it.mauriziulu.android.ehttpexecutors.util.SystemUtil;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

public class ConnectionVerifierHandler implements EResponseHandler {

	public ConnectionVerifierHandler() {
	}

	@Override
	public void handle(EHttpRequest request, EHttpResponseContainer response, ResponseHandlerChain chain) throws ClientProtocolException, IOException {
		if (SystemUtil.isNetworkAvailable(chain.getAndroidContext())) {
			response.addMessage("Connection OK");
			chain.doHandle(request, response);
		} else {
			response.addMessage("Connection not available!");
			throw new IOException("Connection unavailable");
		}
	}

}
